import { Body, Controller, Delete, Get, Param, Post, Put, Query } from '@nestjs/common'
import { ApiOperation, ApiTags } from '@nestjs/swagger'
import { ApiSecurityAuth } from '~/common/decorators/swagger.decorator'
import { definePermission, Perm } from '~/modules/admin/auth/decorators/permission.decorator'
import { CreateBookTagDto } from '../dto/create-book-tag.dto'
import { QueryBookTagDto } from '../dto/query-book-tag.dto'
import { UpdateBookTagDto } from '../dto/update-book-tag.dto'
import { BookTagService } from '../services/book-tag.service'

export const permissions = definePermission('study:book:tag', {
  CREATE: 'create',
  UPDATE: 'update',
  DELETE: 'delete',
} as const)

@ApiTags('Study - 书籍标签管理')
@ApiSecurityAuth()
@Controller('admin/study/book/book-tag')
export class BookTagController {
  constructor(private readonly bookTagService: BookTagService) {}

  @Post()
  @ApiOperation({ summary: '创建书籍标签' })
  @Perm(permissions.CREATE)
  create(@Body() createBookTagDto: CreateBookTagDto) {
    return this.bookTagService.create(createBookTagDto)
  }

  @Get()
  @ApiOperation({ summary: '获取书籍标签列表' })
  findAll(@Query() queryBookTagDto: QueryBookTagDto) {
    return this.bookTagService.findAll(queryBookTagDto)
  }

  @Get(':id')
  @ApiOperation({ summary: '获取书籍标签详情' })
  findOne(@Param('id') id: string) {
    return this.bookTagService.findOne(+id)
  }

  @Put(':id')
  @ApiOperation({ summary: '更新书籍标签' })
  @Perm(permissions.UPDATE)
  update(@Param('id') id: string, @Body() updateBookTagDto: UpdateBookTagDto) {
    return this.bookTagService.update(+id, updateBookTagDto)
  }

  @Delete(':id')
  @ApiOperation({ summary: '删除书籍标签' })
  @Perm(permissions.DELETE)
  remove(@Param('id') id: string) {
    return this.bookTagService.remove(+id)
  }
}
